package cqu.mvc.model;



import cqu.mvc.HibernateUtil;
import org.hibernate.Session;
import org.hibernate.query.Query;

import java.util.List;

/**
 * 文件DAO
 * 对应disk数据库中的fileentity表
 */
public class FileDao {
	public static void addFile(String id, String name,UserEntity user) {
		FileEntity fileEntity = new FileEntity(id, name, user);
		HibernateUtil.commitEntity(fileEntity);
	}


	public static List<FileEntity> getFileByUser(String username) {

		try (Session session = HibernateUtil.getSession()) {
			Query<FileEntity> q = session.createQuery("from FileEntity where user_name='" + username + "'", FileEntity.class);
			return q.list();
		}

	}

}
